import { createBrowserRouter, Navigate } from "react-router-dom";
import Article from "../pages/Article/Article";
import Detail from "../pages/Detail/Detail";
import From from "../pages/From/From";
import Home from "../pages/Home/Home"
import Login from "../pages/Login/Login";
import My from "../pages/My/My";
import User from "../pages/User/User";
import Layouts from "../Layouts/Layouts";
function Adssw({children}){
    const save=localStorage.getItem('token')
    return save?children:<Navigate to={'/login'} />
}
export const routerlist=[
    {
        path:'/home',
        element:<Home />,
        meta:{title:'首页'},
    },
    {
        path:'/article',
        meta:{title:'列表页'},
        children:[
            {
                path:'/article/li',
                element:<Adssw><Article /></Adssw>,
                meta:{title:'卡片列表'}
            },
            {
                path:'/article/detail',
                element:<Adssw><Detail /></Adssw>,
                meta:{title:'查询列表'}
            }
        ]
    },
    {
        path:'/from',
        
        meta:{title:'表单页'},
        children:[
            {
                
                path:'/from/li',
                element:<From />,
                meta:{title:'表单'}
            
            },
            {
                
                path:'/from/my',
                element:<My />,
                meta:{title:'表单er'}
            
            }
        ]
    },
    
    {
        path:'/user',
        element:<User />,
        meta:{title:'系统管理'},
    }
]

const router=createBrowserRouter([
    {
        path:'/',
        element:<Layouts />,
        children:routerlist
    },
    {
        path:'/login',
        element:<Login />
    }
])

export default router